<html>
<head><meta charset="utf-8"><title>Design of eager macro expansion · t-compiler/rust-analyzer · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/index.html">t-compiler/rust-analyzer</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Design.20of.20eager.20macro.20expansion.html">Design of eager macro expansion</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="218351700"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Design%20of%20eager%20macro%20expansion/near/218351700" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Design.20of.20eager.20macro.20expansion.html#218351700">(Nov 30 2020 at 21:55)</a>:</h4>
<p>In rustc, eager expansion is implemented with a single line of code:</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="kd">let</span><span class="w"> </span><span class="n">expr</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">cx</span><span class="p">.</span><span class="n">expander</span><span class="p">().</span><span class="n">fully_expand_fragment</span><span class="p">(</span><span class="n">AstFragment</span>::<span class="n">Expr</span><span class="p">(</span><span class="n">expr</span><span class="p">)).</span><span class="n">make_expr</span><span class="p">();</span><span class="w"></span>
</code></pre></div>
<p>In rust-analyzer, a comparatively huge amount of infrastructure seems to be responsible for handling eager macros. Is that a necessary consequence of doing it in a query-driven way, or is this complexity accidental and could be reduced?</p>



<a name="218364582"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Design%20of%20eager%20macro%20expansion/near/218364582" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Design.20of.20eager.20macro.20expansion.html#218364582">(Dec 01 2020 at 00:09)</a>:</h4>
<p>Ah, just found this thread: <a href="#narrow/stream/131828-t-compiler/topic/Eager.20expansion.20of.20built-in.20macros">https://rust-lang.zulipchat.com/#narrow/stream/131828-t-compiler/topic/Eager.20expansion.20of.20built-in.20macros</a></p>



<a name="218427587"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Design%20of%20eager%20macro%20expansion/near/218427587" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Design.20of.20eager.20macro.20expansion.html#218427587">(Dec 01 2020 at 14:21)</a>:</h4>
<p>Yeah, it's true that, overall, "eager macros are tricky". Our current impl is not in cache for me though it's quite likely we can simplify it substantionally. </p>
<p>IIRC, we just encode the whole of macro argument into macro ID for eager expansion.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>